package DFS;

import java.util.ArrayList;
import java.util.List;

public class Solution78 {


    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3};

        System.out.println(subsets(nums));
    }

    public static List<List<Integer>> subsets(int[] nums) {
        List<Integer> chain = new ArrayList<>();
        List<List<Integer>> res = new ArrayList<>();
        dfs(nums, 0, chain, res);
        return res;
    }


    public static void dfs(int[] nums, int index, List<Integer> chain, List<List<Integer>> res) {
        res.add(new ArrayList<>(chain));
        if (index >= nums.length) {
            return;
        }
        for (int i = index; i < nums.length; i++) {
            chain.add(nums[i]);
            dfs(nums, i + 1, chain, res);
            chain.remove(chain.size() - 1);
        }
    }
}
